//
//  AddShopPicture.m
//  Findif
//
//  Created by Mac on 2018/11/7.
//  Copyright © 2018年 Cicel Chen. All rights reserved.
//

#import "AddShopPicture.h"

@interface AddShopPicture ()

@property (nonatomic, strong)UIButton * oneButton;
@property (nonatomic, strong)UIButton * twoButton;
@property (nonatomic, strong)UIButton * threeButton;
@property (nonatomic, strong)UIButton * fourButton;
@property (nonatomic, strong)UIButton * fiveButton;
@property (nonatomic, strong)UIButton * sixButton;
@property (nonatomic, strong)UIButton * sevenButton;
@property (nonatomic, strong)UIButton * eightButton;
@property (nonatomic, copy)NSString * oneString;
@property (nonatomic, copy)NSString * twoString;
@property (nonatomic, copy)NSString * threeString;
@property (nonatomic, copy)NSString * fourString;
@property (nonatomic, copy)NSString * fiveString;
@property (nonatomic, copy)NSString * sixString;
@property (nonatomic, copy)NSString * sevenString;
@property (nonatomic, copy)NSString * eightString;

@end

@implementation AddShopPicture


- (instancetype)initWithFrame:(CGRect)frame{
    
    if ([super initWithFrame:frame]) {
        
        [self setupUI];
    }
    
    return self;
}


- (void)setCount:(NSInteger )count{
    
    _count = count;
    
    switch (count) {
        case 1:
            self.twoButton.hidden = NO;
            break;
        case 2:
            self.threeButton.hidden = NO;
            break;
        case 3:
            self.fourButton.hidden = NO;
            break;
        case 4:
            self.fiveButton.hidden = NO;
            break;
        case 5:
            self.sixButton.hidden = NO;
            break;
        case 6:
            self.sevenButton.hidden = NO;
            break;
        case 7:
            self.eightButton.hidden = NO;
            break;
//        case 8:
//            self.nineButton.hidden = NO;
//            break;
        default:
            break;
    }
}


- (void)setButtonImage:(UIImage *)buttonImage{
    
    _buttonImage = buttonImage;
    
    switch (self.count) {
        case 1:
            [self.oneButton setImage:buttonImage forState:UIControlStateNormal];
            break;
        case 2:
            [self.twoButton setImage:buttonImage forState:UIControlStateNormal];
            break;
        case 3:
            [self.threeButton setImage:buttonImage forState:UIControlStateNormal];
            break;
        case 4:
            [self.fourButton setImage:buttonImage forState:UIControlStateNormal];
            break;
        case 5:
            [self.fiveButton setImage:buttonImage forState:UIControlStateNormal];
            break;
        case 6:
            [self.sixButton setImage:buttonImage forState:UIControlStateNormal];
            break;
        case 7:
            [self.sevenButton setImage:buttonImage forState:UIControlStateNormal];
            break;
        case 8:
            [self.eightButton setImage:buttonImage forState:UIControlStateNormal];
            break;
//        case 9:
//            [self.nineButton setImage:buttonImage forState:UIControlStateNormal];
//            break;
        default:
            break;
    }
}


- (void)setupUI{
    
    self.backgroundColor = [UIColor whiteColor];
    
    self.oneButton = [self setupButton];
    self.oneButton.tag = 1;
    [self addSubview:self.oneButton];
    self.twoButton = [self setupButton];
    self.twoButton.tag = 2;
    [self addSubview:self.twoButton];
    self.threeButton = [self setupButton];
    self.threeButton.tag = 3;
    [self addSubview:self.threeButton];
    self.fourButton = [self setupButton];
    self.fourButton.tag = 4;
    [self addSubview:self.fourButton];
    self.fiveButton = [self setupButton];
    self.fiveButton.tag = 5;
    [self addSubview:self.fiveButton];
    self.sixButton = [self setupButton];
    self.sixButton.tag = 6;
    [self addSubview:self.sixButton];
    self.sevenButton = [self setupButton];
    self.sevenButton.tag = 7;
    [self addSubview:self.sevenButton];
    self.eightButton = [self setupButton];
    self.eightButton.tag = 8;
    [self addSubview:self.eightButton];
//    self.nineButton = [self setupButton];
//    self.nineButton.tag = 9;
//    [self addSubview:self.nineButton];
//    self.tenButton = [self setupButton];
//    self.tenButton.tag = 10;
//    [self addSubview:self.tenButton];
    
    self.oneButton.hidden = NO;
}

-(void)layoutSubviews{
    
    [self.oneButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self).offset(10 * SCREENH6);
        make.top.mas_equalTo(self).offset(5 * SCREENH6);
        make.width.mas_equalTo(77 * SCREENH6);
        make.height.mas_equalTo(60 * SCREENH6);
    }];
    
    [self.twoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.oneButton.mas_trailing).offset(5 * SCREENH6);
        make.centerY.width.height.mas_equalTo(self.oneButton);
    }];
    
    [self.threeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.twoButton.mas_trailing).offset(5 * SCREENH6);
        make.centerY.width.height.mas_equalTo(self.twoButton);
    }];
    
    [self.fourButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.threeButton.mas_trailing).offset(5 * SCREENH6);
        make.centerY.width.height.mas_equalTo(self.threeButton);
    }];
    
    [self.fiveButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.oneButton.mas_bottom).offset(5 * SCREENH6);
        make.leading.width.height.mas_equalTo(self.oneButton);
    }];
    
    [self.sixButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.fiveButton.mas_trailing).offset(5 * SCREENH6);
        make.centerY.width.height.mas_equalTo(self.fiveButton);
    }];
    
    [self.sevenButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.sixButton.mas_trailing).offset(5 * SCREENH6);
        make.centerY.width.height.mas_equalTo(self.sixButton);
    }];
    
    [self.eightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.sevenButton.mas_trailing).offset(5 * SCREENH6);
        make.centerY.width.height.mas_equalTo(self.sevenButton);;
    }];
    
//    [self.nineButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.eightButton.mas_trailing).offset(5 * SCREENH6);
//        make.centerY.width.height.mas_equalTo(self.eightButton);;
//    }];
//
//    [self.tenButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.nineButton.mas_trailing).offset(5 * SCREENH6);
//        make.centerY.width.height.mas_equalTo(self.nineButton);;
//    }];
}


- (UIButton *)setupButton{
    
    UIButton * button = [UIButton new];
    
    //    [button setBackgroundColor:[UIColor lightGrayColor]];
    [button setImage:[UIImage imageNamed:@"添加图片"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(iconBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    button.hidden = YES;
    
    return button;
}

- (void)iconBtnClick:(UIButton *)button{
    
    //    [[NSNotificationCenter defaultCenter] postNotificationName:@"test" object:nil];
    if (self.addShopPictureDelegate && [self.addShopPictureDelegate respondsToSelector:@selector(clickItemButton:)])
    {
        [self.addShopPictureDelegate clickItemButton:button.tag];
    }
}

@end
